package com.wms.controller;

import com.wms.bean.PageBean;
import com.wms.bean.ResultBean;
import com.wms.core.R;
import com.wms.dto.*;
import com.wms.entity.Allocate;
import com.wms.entity.AllocateDetailAudit;
import com.wms.entity.Allocatedetail;
import com.wms.service.AllocateService;
import com.wms.service.AllocatedetaiAuditService;
import com.wms.service.AllocatedetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/allocateaudit")
@Api(tags = "调拨审核业务--张开心")
@Slf4j
public class AllocatedetaiAuditController {
    @Autowired
    AllocatedetaiAuditService allocatedetaiAuditService;

    @Autowired
    private AllocatedetailService allocatedetailService;

    @PostMapping("/query")
    @ApiOperation(value = "条件以模糊及所有查询调度审核单")
    public ResultBean<PageBean<List<AllocateDetailAudit>>> query(
            @ApiParam(value = "调拨单审核条件", required = true) @RequestBody AllocatedetailAuditDTO allocatedetailAuditDTO
    ) {
        log.info("条件查询调度审核单{}", allocatedetailAuditDTO);
        PageBean<List<AllocateDetailAudit>> pageBean = allocatedetaiAuditService.query(allocatedetailAuditDTO);
        return pageBean.getList().size() != 0 ? R.success("查询成功", pageBean) : R.fail("查询失败");
    }

    @PostMapping("/audit")
    @ApiOperation(value = "审核调度是否通过")
    public ResultBean<Integer> audit(
            @ApiParam(value = "调拨单审核条件", required = true) @RequestBody AllocatedetailAuditVo allocatedetailAuditVo
    ) {
        log.info("审核调度是否通过{}", allocatedetailAuditVo);
        int rows = allocatedetaiAuditService.update(allocatedetailAuditVo);
        return rows==1?R.success("审核成功"):R.fail("操作失败");
    }


    @GetMapping("/pass/{id}")
    @ApiOperation(value = "查看审核通过的信息")
    public ResultBean queryPass(
            @ApiParam(value = "查看审核通过的信息的id", required = true)@PathVariable Integer id
    ) {
        log.info("查看审核通过的信息的id{}", id);
        List<TransferPassDTO> list = allocatedetaiAuditService.selectPass(id);
        return list.size()!=0?R.success("查询成功",list):R.fail("操作失败");
    }


}
